<?php
/* ************************************************** *\
 * @company		: NovaITech							  *	
 * @author		: van.vo@novaitech.com				  * 
 * @copyright	: 2012								  * 
 * ================================================== *
 * @date		: 03/19/2012
 * @project		: CodeGenerator
 * @description	:
 *		- 
 *
\* ************************************************** */

class design extends MY_Controller
{
	function __construct( )
	{
		parent::__construct( );
	}
	
	function index()
	{
        if($this->input->post('generator')){
            $data['actions']                =   $this->input->post( 'action' );
            $data['custom_actions']         =   $this->input->post( 'custom_action' );
            
            $data['master_view']    =   is_array( $this->input->post( 'master' ) ) ? $this->input->post( 'master' ) : array( );    
            $data['detail_view']    =   is_array( $this->input->post( 'detail' ) ) ? $this->input->post( 'detail' ) : array( );
            
            $data['labels']         =   $this->input->post( 'labels' );
            
            $data['display_types']  =   $this->input->post( 'type' );
            
            $data['records']        =   $this->input->post( 'records' );
    
            $data['rules']          =   $this->input->post( 'rules' );
            
            $data['controller']     =   $this->input->post( 'controller' );
            $data['view']           =   $this->input->post( 'view' );
            $data['validation']     =   $this->input->post( 'validation' );
            $data['table']          =   $this->input->post( 'table' );
            $data['primarykey']     =   $this->input->post( 'primaryKey' );
            
            $this->xml_model->save_to_xml($data);
            $this->load->view('design_view', $data);
        }else{
            echo "Restricted access to this file.";
        }             
	}
    

   
    // Add new $data to field $parent_field in $table
    function add_child_node($table_name, $data, $parent_field){
        $this->xml_model->add_child_node($table_name, $data, $parent_field);   
    }
   
    // Insert $id, $value to $parent_field in $table
    // Flags:
    //      false: insert control value
    //      true : insert control type
    function save_control($table, $id, $value, $control_type, $parent_field , $selected = NULL, $flags = false){

        $this->xml_model->save_control($table, $id, $value, $control_type, $parent_field, $selected, $flags);
    }
    
    // Load control (radio, checkbox, combobox)
    function load_control($data = NULL){
        $d['data'] = $data; // item selected in detail
        $d['table'] = $this->input->post('table'); // table contain field selected
        $this->load->view('childform/data_view', $d); 
    } 
    
    // Show form add radio control
    function add_radio($data){
        $arr['selected_item'] = $data;  // item selected in detail view
        $arr['table']   =   $this->input->post('table');
        $this->load->view('childform/data_radio', $arr);                  
    }
    // Show form add checkbox control
    function add_checkbox($data){
        $arr['selected_item'] = $data;  // item selected in detail view
        $arr['table']   =   $this->input->post('table');
        $this->load->view('childform/data_checkbox.php', $arr);            
    }
    
    // Show form add combobox control
    function add_combobox($data){
        $arr['selected_item'] = $data;  // item selected in detail view
        $arr['table']   =   $this->input->post('table');
        $this->load->view('childform/data_combobox.php', $arr);            
    }
    
    // Show form add listbox control
    function add_listbox($data){
        $arr['selected_item'] = $data;  // item selected in detail view
        $arr['table']   =   $this->input->post('table');
        $this->load->view('childform/data_listbox.php', $arr);            
    }
}
?>